import clickhouse_driver
import pandas as pd


class click_db:
    def __init__(self):
        self.client = clickhouse_driver.Client(
            # host="192.168.8.10",# 西安运行时，使用该host
            host="10.20.30.1", # 河津运行时，使用该host
            port=9000,
            user="default",
            password="123456",
            database="keyword"
        )

    def read_sql(self, sql):
        data, columns = self.client.execute(sql, columnar=True, with_column_types=True)
        df = pd.DataFrame({col[0]: d for d, col in zip(data, columns)})
        return df

